const { Sequelize, DataTypes } = require('sequelize')
const sequelize = new Sequelize('serialDB', 'root', 'root', {
	host: 'localhost',
	dialect: 'mysql',
})
// async function testConnection() {
// 	try {
// 		await sequelize.authenticate()
// 		console.log('Connection has been established successfully.')
// 	} catch (error) {
// 		console.error('Unable to connect to the database:', error)
// 	}
// }

const hangk = sequelize.define('hangk', {
	id: {
		type: DataTypes.INTEGER,
		primaryKey: true,
		autoIncrement: true,
	},
	hour: {
		type: DataTypes.STRING,
	},
	minute: {
		type: DataTypes.STRING,
	},
	second: {
		type: DataTypes.STRING,
	},
	weidu: {
		type: DataTypes.STRING,
	},
	weiduP: {
		type: DataTypes.STRING,
	},
	jingdu: {
		type: DataTypes.STRING,
	},
	jingduP: {
		type: DataTypes.STRING,
	},
	altitude: {
		type: DataTypes.STRING,
	},
	height: {
		type: DataTypes.STRING,
	},
	normalSpeed: {
		type: DataTypes.STRING,
	},
	course: {
		type: DataTypes.STRING,
	},
	year: {
		type: DataTypes.STRING,
	},
	month: {
		type: DataTypes.STRING,
	},
	day: {
		type: DataTypes.STRING,
	},
	valid: {
		type: DataTypes.STRING,
	},
	uid: {
		type: DataTypes.STRING,
	},
})

// 同步模型到数据库
// !(async () => {
// 	try {
// 		await sequelize.sync()
// 		console.log('模型创建成功！')
// 	} catch (error) {
// 		console.error('模型创建失败：', error)
// 	} finally {
// 		sequelize.close() // 关闭数据库连接
// 	}
// })()

// 插入数据
let data = {
	hour: '12',
	minute: '12',
	second: '12',
	weidu: '12',
	weiduP: '12',
	jingdu: '12',
	jingduP: '12',
	altitude: '12',
	height: '12',
	normalSpeed: '12',
	course: '12',
	year: '12',
	month: '12',
	day: '12',
	valid: '12',
	uid: '12',
}
async function ins() {
	await hangk.create(data)
	sequelize.close()
}
console.log(ins())
